package com.mall.server.service.ums;

import com.mall.autoconfig.exception.BusinessException;
import com.mall.dubbo.api.UmsResourceApi;
import com.mall.dubbo.api.UmsResourceCategoryApi;
import com.mall.model.domain.UmsResourceCategory;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author : xyiaao
 * @createDate : 2022/3/31 12:09
 */
@Service
public class UmsResourceCategoryService {

    @DubboReference
    private UmsResourceCategoryApi umsResourceCategoryApi;


    @DubboReference
    private UmsResourceApi umsResourceApi;

    public void create(UmsResourceCategory umsResourceCategory) {

        umsResourceCategory.setCreateTime(new Date());
        umsResourceCategoryApi.save(umsResourceCategory);
    }

    public void delete(Integer id) {

        if (!umsResourceCategoryApi.delete(id)) {
            throw new BusinessException("该分类下有资源，无法删除");
        }
    }

    public List<UmsResourceCategory> listAll() {

        return umsResourceCategoryApi.listAll();
    }

    public void update(UmsResourceCategory umsResourceCategory) {

        umsResourceCategoryApi.updateById(umsResourceCategory);
    }

}
